<body class="app" data-ad="true">
<?php $CDN= $this->CommonHelper()->imageDomain();?>
<section class="app-content">
	<section class="page page-index noline" data-plugin-type="info_front">

        <article class="shop-message">
            <dl>
                <dt class="shop-l">
                    <img src="<?php echo "{$CDN}{$this->orgInfo['org_thumb_image']}";?>">
                </dt>
                <dd>
                    <h2 class="sp-title"><?php echo $this->orgInfo['org_title'];?>配餐/商城<span><?php echo $this->orgInfo['org_level'];?></span></h2>
                    <!--<div class="sp-des"><?php echo $this->orgInfo['org_subtitle'];?> </div>-->
                    <div class="sp-notice" id="marquee">
                        <div><span>公告：<?php echo $this->orgInfo['org_advice'];?></span></div>
                    </div>
                </dd>
            </dl>
            <a class="ico-arr ico-search-grey btn-shop-search" href="/index/search"></a>
            <a class="btn-collect" href="javascript:collect('<?php echo $this->org_id;?>');">收 藏</a>
        </article>
        <div class="bw shop-tab">
            <ul class="prod-nav zoom">
                <li><a href="<?php echo "/organization/vMerchant/{$this->org_id}" ?>" class="on">餐品/商品</a></li>
                <li><a href="<?php echo "/organization/vSeller/{$this->org_id}"?>">商 家</a></li>
            </ul>
        </div>

        <div class="shop-ct-block">
            <!-- 左边菜单-->
            <div class="sp-l-nav">
                <ul>
                    <?php if(count($this->category)>0):?>
                    <?php foreach ($this->category as $cateKey => $categoryItem):?>
                    <li class="category_btn <?php if($cateKey == 0):?>on<?php endif;?>"><a href="#proItem_<?php echo $categoryItem['category_id'];?>"><?php echo $categoryItem['category_name'];?></a></li>
                    <?php endforeach;?>
                    <?php endif;?>
                </ul>
            </div>
            <!-- 右边内容-->
            <div class="sp-r-ct">
				<?php if(count($this->category)>0):?>
				<?php foreach ($this->category as $cateKey => $categoryItem):?>
				<div id="proItem_<?php echo $categoryItem['category_id'];?>">
				<?php if(count($categoryItem['productList'])>0):?>
				<?php foreach ($categoryItem['productList'] as $proKey => $productItem):?>
					<input id="proImgBig_<?php echo $productItem['product_id'];?>" type="hidden"  value="<?php echo "{$CDN}{$productItem['product_big_image']}";?>" >
                    <dl class="sp-item">
                        <dt><a href="javascript:suyuan('<?php echo $productItem['product_id'];?>');" class="sp-btn-origin"><img src="<?php echo "{$CDN}{$productItem['product_thumb_image']}";?>"></a></dt>
                        <dd>
                            <h3><a href="javascript:suyuan(<?php echo $productItem['product_id'];?>);" class="sp-btn-origin" id="proName_<?php echo $productItem['product_id'];?>"><?php echo $productItem['product_name'];?></a></h3>
                            <h4 id="proDes_<?php echo $productItem['product_id'];?>">简介：<?php echo $productItem['product_description'];?></h4>
                            <h5>规格：5kg／袋</h5>
                            <p class="price">￥<span id="proPrice_<?php echo $productItem['product_id'];?>" class="p-num"><?php echo $productItem['product_price'];?></span></p>
                            <div class="ope-line">
                                <a class="btn-ope btn-ope-minus" href="javascript:proMinus('<?php echo $productItem['product_id'];?>');"></a><span class="sp-ope-num">0</span><a class="btn-ope btn-ope-plus" href="javascript:proAdd('<?php echo $productItem['product_id'];?>');"></a>
                            </div>
                        </dd>
                    </dl>
				<?php endforeach;?>
				<?php endif;?>
				</div>
				<?php endforeach;?>
				<?php endif;?>
            </div>
        </div>

	</section>

    <div class="total-bar" style="bottom: 95px;">
	     <form id="orderForm" action="/order/index" method='post'>
	        <input id="org_id" name="org_id" type="hidden" value="<?php echo $this->org_id;?>">
	        <input id="proList" name="proList" type="hidden" value="">
	        <input id="numList" name="numList" type="hidden" value="">
	        <a class="btn-yel btn-statement" href="javascript:goOrder();">去结算</a>
	        <span class="t-num">件数<i id="total_num">0</i></span>
	        <span class="t-price">合计  ¥ <i id="total_price">0.00</i></span>
	    </form>
    </div>
    <!-- 底部menu-->
    <?php echo $this->partial('public/menu.phtml'); ?>
</section>
<!-- div class="bgMask"></div>
<div class="popup popup-shop">
    <img  class="pop-s-img" src="/mobile/images/temp/pop-shop.jpg">
    <div class="pop-s-ct">
        <h3 class="pop-s-title">商品／套餐A</h3>
        <div class="pop-s-des">鸿益配餐精制的鱼香肉丝套餐全部采用有机原 材料制作而成，营养美味，健康可口...</div>
        <h3 class="pop-s-material">用 料</h3>
        <div class="info-ct">
            <ul class="pop-s-uladd">
            </ul>
        </div>
        <a href="javascript:goOrder();" class="btn-buy mb20">购 买</a>
    </div>

</div -->
<script type="text/javascript">
$('.shop-description').hide();
$(function () {
    var myH = document.body.clientHeight-485;//去掉头部及页面底部固定内容
    //console.log(myH);
    $('.shop-ct-block,.sp-l-nav,.sp-r-ct').height(myH);
    $('.shop-description').height(myH);
    //类目点击
    $('.category_btn').click(function(){
        $('.category_btn').removeClass("on");
        $(this).addClass("on");
    })
    //隐藏溯源
    $('.bgMask').click(function(){
        $('.bgMask,.popup-shop').hide();
    })
    //显示商品
    $('#product_show').click(function(){
        $('.shop-ct-block').show();
        $('#product_show').addClass("on");
        $('.shop-description').hide();
        $('#description_show').removeClass("on");
    })
    //显示商店描述
    $('#description_show').click(function(){
        $('#product_show').removeClass("on");
        $('.shop-ct-block').hide();
        $('#description_show').addClass("on");
        $('.shop-description').show();
    })
});
var isPost = false;

//溯源显示

function suyuan(proId){
	return false;
	/**
    $('.pop-s-img').attr("src",$("#proImgBig_"+proId).val());
    $('.pop-s-title').text($("#proName_"+proId).text());
    $('.pop-s-des').text($("#proDes_"+proId).text());
    if(!isPost){
        isPost = true;
        $.ajax({
            url: '/organization/material',
            type: 'post',
            data: {
                'product_id': proId,
                },
            dataType: 'json',
            timeout: 200000,
            success: function (json) {
                isPost = false;
                if (json.result) {
                    var html="";
                    var material_id = "";
                    for(var i=0;i<json.data.length;i++){
                        material_id = json.data[i].material_id;
                        html += '<li><span>'+ json.data[i].material_name +'</span><a href="javascript:;" class="btn-s-origin">溯 源</a></li>';
                    }
                    $('.pop-s-uladd').html(html);
                    $('.popup-shop').show();
                } else {
                    alert(json.reason);
                }
            },
            error: function (err) {
                isPost = false;
                alert('请求超时，请重新操作');
                return false; 
            }
        });
    }
    
    $('.bgMask').show();
    */
}


var productList =  new Array();
var numList =  new Array();
//增加商品
function proAdd(proId){
    var total_num = parseFloat($('#total_num').text()) + 1;
    var total_price = parseFloat($('#total_price').text()) + parseFloat($("#proPrice_"+proId).text());
    $('#total_num').text(total_num);
    $('#total_price').text(toDecimal2(total_price));
    var flg =true;
    for (var i=0 ; i < productList.length ; ++i ){
        if(productList[i] == proId){
            numList[i] = numList[i] + 1;
            flg = false;
        }
    } 
    if(flg){
        productList.push(proId);
        numList.push(1);
    }
}
//减少商品
function proMinus(proId){
    var total_num = parseFloat($('#total_num').text()) - 1;
    var total_price = parseFloat($('#total_price').text()) - parseFloat($("#proPrice_"+proId).text());
    $('#total_num').text(total_num);
    $('#total_price').text(toDecimal2(total_price));
    for (var i=0 ; i < productList.length ; ++i ){
        if(productList[i] == proId){
            numList[i] = numList[i] - 1;
            if(numList[i] == 0){
                delete productList[i];
                delete numList[i];
            }
        }
    }
}
//去结算
function goOrder(){
    var total_num = parseFloat($('#total_num').text());
    if(total_num == 0){
        alert("请先选择商品！");
        return false;
    }
    $("#proList").val(productList.join("|"));
    $("#numList").val(numList.join("|"));
    $("#orderForm").submit();
}
//收藏
function collect(orgId){
    if(!isPost){
        isPost = true;
        $.ajax({
            url: '/organization/collect',
            type: 'post',
            data: {
                'orgId': orgId,
                },
            dataType: 'json',
            timeout: 200000,
            success: function (json) {
                isPost = false;
                alert(json.reason);
            },
            error: function (err) {
                isPost = false;
                alert('请求超时，请重新操作');
                return false; 
            }
        });
    }
}
</script>